import { useContext } from "react";
import { Button } from "@douyinfe/semi-ui";
import { IconLanguage } from "@douyinfe/semi-icons";
import { GlobalContext } from "@/context";
import type { ButtonProps } from "@douyinfe/semi-ui/lib/es/button/Button";

const Locale = (props: ButtonProps) => {
  const { setLang, lang } = useContext(GlobalContext);

  return (
    <Button
      icon={<IconLanguage />}
      {...props}
      onClick={() => setLang && setLang(lang === "zh-CN" ? "en-US" : "zh-CN")}
    >
      {lang == "zh-CN" ? "中" : "En"}
    </Button>
  );
};

export default Locale;
